package com.example.tests;


import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;

public class GroupCreationTests extends TestBase {
	
  @Test
  public void testNonEmptyGroupCreation() throws Exception {
	app.getNavigationHelper().openMainPage();
    app.getNavigationHelper().goToGroupsPage();
    
    //save old state
    
    List<GroupData> oldlist = app.getGroupHelper().getGroups();
    //action
    app.getGroupHelper().initGroupsCreation();
    GroupData group = new GroupData();
    group.name = "groupName_1";
    group.header = "header 1";
    group.footer = "footer 1";
	app.getGroupHelper().fillGroupForm(group);
    app.getGroupHelper().submitGroupPage();
    app.getGroupHelper().returnToGroupPage();
    
    
    //save new state
    List<GroupData> newlist = app.getGroupHelper().getGroups();
    
   // compare new state
    oldlist.add(group);
    Collections.sort(oldlist);
    assertEquals(newlist, oldlist);
    
  }
  

@Test
  public void testEmptyGroupCreation() throws Exception {
	app.getNavigationHelper().openMainPage();
    app.getNavigationHelper().goToGroupsPage();
    
    
  //SAVE OLD STATE 
    
    List<GroupData> oldlist = app.getGroupHelper().getGroups();
    
  //action
   
   
    app.getGroupHelper().initGroupsCreation();
    GroupData group = new GroupData("","","");
	app.getGroupHelper().fillGroupForm(group);
    app.getGroupHelper().submitGroupPage();
    app.getGroupHelper().returnToGroupPage();
    //save new state
    List<GroupData> newlist = app.getGroupHelper().getGroups();
    
   // compare new state
    oldlist.add(group);
    Collections.sort(oldlist);
    assertEquals(newlist, oldlist);
    app.getNavigationHelper().goToHomePage();
  }
  
}

